package xyz.scootaloo.mono.admin

import cn.hutool.log.LogFactory
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import xyz.scootaloo.mono.base.service.async.AsyncTaskService
import xyz.scootaloo.mono.base.service.async.TaskDefinition

@SpringBootTest
class MonoAdminApplicationTests {

    val log = LogFactory.get()

    @Test
    fun contextLoads() {
    }

    @Test
    fun testAsyncTask() {
        val taskDefinition = TaskDefinition(::task).apply {
            onNext { value ->
                log.info("${value + 3}")
            }
            onError { throwable ->
                log.info("抛出异常: ${throwable.message}")
            }
        }
        async.taskWithCallback(taskDefinition, 3000)
        Thread.sleep(7000)
    }

    fun task(): Int = 5

    @Autowired lateinit var async: AsyncTaskService
}
